<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Login extends CI_Controller {

	/**
	 * Index Page for this controller.
	 *
	 * Maps to the following URL
	 * 		http://example.com/index.php/welcome
	 *	- or -  
	 * 		http://example.com/index.php/welcome/index
	 *	- or -
	 * Since this controller is set as the default controller in 
	 * config/routes.php, it's displayed at http://example.com/
	 *
	 * So any other public methods not prefixed with an underscore will
	 * map to /index.php/welcome/<method_name>
	 * @see http://codeigniter.com/user_guide/general/urls.html
	 */
	 
	public function __construct() {
		parent::__construct();
		//var_dump($_POST);
	}
	public function index($variable=NULL)
	{
		$this->load->helper('url');
		$content['url']=base_url();
		$this->load->view('template/html/login.php',$content);
		
	}	
	
	public function submit(){
		$this->load->library('doctrine');

		
		
			##service adicionales###
		$this->load->library('serviceuser');


		if($this->input->post('usuario')!=''  && $this->input->post('password')!=''){

		
			$datos=$this->serviceuser->login($this->input->post('usuario'),$this->input->post('password'));
			
				if(count($datos)==0){
					redirect('login','location',301);

				}else{
					$usuario['id']=$datos[0]['iduser'];
					$usuario['usuario']=$datos[0]['usuario'];
					$usuario['tiempo']=time();

					
					
					$this->session->set_userdata('usuario',$usuario);
					redirect('administracion','location',301);	
					
				}
				
			}
		}
	public function logout(){
		$this->load->library('session');
		$this->load->helper('url');
		
		
		$usuario=$this->session->userdata('usuario');
		$this->session->unset_userdata('usuario');
		header('Location:'.base_url().'login');	
		}
	
	
}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */